#include "ParseFormatTestSuite.h"
#include <cstddef>
#if __cplusplus >= 201402L

#    include <gtest/gtest.h>
#    include "LoggerNew.h"
using namespace xncc;
TEST_F(ParseFormatTestSuite, getFormatParamsCountNoParams)
{
    EXPECT_EQ(getFormatParamsCount("tests string"), 1);
}

TEST_F(ParseFormatTestSuite, getFormatParamsCountOneParams)
{
    EXPECT_EQ(getFormatParamsCount("tests string %d"), 2);
}

TEST_F(ParseFormatTestSuite, getFormatParamsCountOneParamsNoString)
{
    EXPECT_EQ(getFormatParamsCount("%d"), 2);
}

TEST_F(ParseFormatTestSuite, getFormatParamsCountTwoParams)
{
    EXPECT_EQ(getFormatParamsCount("%d tests string %d"), 3);
}

TEST_F(ParseFormatTestSuite, getFormatParamsCountTwoParamsNoString)
{
    EXPECT_EQ(getFormatParamsCount("%d%d"), 3);
}

TEST_F(ParseFormatTestSuite, getFormatParamsCountPercentSign)
{
    EXPECT_EQ(getFormatParamsCount("%%%d"), 2);
}

TEST_F(ParseFormatTestSuite, parseFormatStrNoParams)
{
    static constexpr char        testStr[] = "tests string";
    static constexpr std::size_t len       = sizeof(testStr) - 1;
    auto constexpr rets                    = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, len);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrNoParamsPercentSign)
{
    static constexpr char        testStr[] = "%%tests string";
    static constexpr std::size_t len       = sizeof(testStr) - 1 - 2;
    auto constexpr rets = parseFormatStrPercentSign<getFormatParamsCountPercentSign(testStr)>(testStr);

    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 0);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::PERCENT_SIGN);

    EXPECT_EQ(rets[1].fmtStr, testStr + 2);
    EXPECT_EQ(rets[1].posOrLen, len);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrNoParamsPercentSignEnd)
{
    static constexpr char testStr[] = "tests string%%";
    auto constexpr rets             = parseFormatStrPercentSign<getFormatParamsCountPercentSign(testStr)>(testStr);

    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 12);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::PERCENT_SIGN);

    EXPECT_EQ(rets[1].posOrLen, 0);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrOneParams)
{
    static constexpr char testStr[] = "tests string%d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 12);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[1].posOrLen, 0);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrOneParamsNotEdge)
{
    static constexpr char testStr[] = "tests string%dabc";
    auto constexpr rets             = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 12);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[1].fmtStr, testStr + 14);
    EXPECT_EQ(rets[1].posOrLen, 3);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrOneParamsNoString)
{
    static constexpr char testStr[] = "%d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 0);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[1].posOrLen, 0);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrTwoParams)
{
    static constexpr char testStr[] = "%dtests string%d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 0);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[1].fmtStr, testStr + 2);
    EXPECT_EQ(rets[1].posOrLen, 12);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[2].posOrLen, 0);
    EXPECT_EQ(rets[2].type, PARAM_TYPE::FORMAT_STR_END);
}

TEST_F(ParseFormatTestSuite, parseFormatStrTwoParamsNoString)
{
    static constexpr char testStr[] = "%d%d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCountPercentSign(testStr)>(testStr);
    EXPECT_EQ(rets[0].fmtStr, testStr);
    EXPECT_EQ(rets[0].posOrLen, 0);
    EXPECT_EQ(rets[0].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[1].posOrLen, 0);
    EXPECT_EQ(rets[1].type, PARAM_TYPE::INTEGER);

    EXPECT_EQ(rets[2].posOrLen, 0);
    EXPECT_EQ(rets[2].type, PARAM_TYPE::FORMAT_STR_END);
}
#endif